#ifndef QIMAGEPROCESSSCENE_H
#define QIMAGEPROCESSSCENE_H

#include <QGraphicsScene>
#include "CHardwareFacade.h"
#include <QPainter>
#include <QGraphicsItem>
#include <QStyleOptionGraphicsItem>


#define MOUSSAVI_BACK_IMAGE_RESOURCE    ":/images/resources/MoussaviView.bmp.jpg"
#define ANIBIKE_BACK_IMAGE_RESOURCE    ":/images/AniBikeWall"
#define ANIBIKE_FRONT_IMAGE_RESOURCE    ":/images/AniBikeWallBody"
#define ANIBIKE_PI                      3.1415926535897932384626433832795
#define ANIBIKE_NUMOFRADS               256
#define ANIBIKE_WHEEL_RADIUS            120
#define ANIBIKE_INNER_RAD_RATIO         0.1

class QImageProcessScene : public QGraphicsScene
{
    Q_OBJECT
public:
    QImageProcessScene(int frameHeight,
                       int frameWidth,
                       CHardwareParams* hwParams);

    ~QImageProcessScene();

    void setHardwareParams (CHardwareParams* hwParams);

private:
    QImage m_BackgroundImage;
    QImage m_ForegroundImage;
    QImage m_LoadedImage;
    QImage m_ViewedImage;
    QImage m_ViewedImageRear;
    QImage m_ConvertedImage;
    CHardwareParams* m_HWParams;
    int m_FrameHeight;
    int m_FrameWidth;
    int m_SceneType;

    unsigned char *m_HWData;
    int m_HWDataSize;

    bool m_DrawingBack;
    bool m_DrawingFore;

public:
    void SetFrameHeight(int fheight);
    void SetFrameWidth(int fwidth);
    void SetImagePath(QString path);  
    int GetFrameWidth(void);
    void GetHWData(int *length, unsigned char **data);
    void SetHWData(int length, unsigned char *data);
    void ClearScreen(void);
    QImage& getLoadedImage (void);
    void setLoadedImage (QImage& image);

private:
    void Update();
    void UpdateMoussavi();
    void UpdateAniBike();
    void UpdateUnknown();
    virtual void drawBackground(QPainter *painter, const QRectF &exposed);
    virtual void drawForeground(QPainter *painter, const QRectF &rect);
    void drawMoussavi(QPainter *painter, const QRectF &rect);
    void drawAniBike(QPainter *painter, const QRectF &rect);
    void convertColorDepth(QImage& image);
    void convertPolarPicture(QImage& image, double invisibleRadRatio);
    void convertToHardwareFrame(void);
    void convertToMoussaviFrame(void);
    void convertToAniBikeFrame(void);
    int convertFromMoussaviFrame (void);
    int convertFromAniBikeFrame (void);
    int convertFromHardwareFrame (unsigned char* data, int size);

private:
    enum {
        SCENE_MOUSSAVI = 0,
        SCENE_ANIBIKE,
        SCENE_UNKNOWN
    };
};

#endif // QIMAGEPROCESSSCENE_H
